#include <iostream>
using namespace std;

int n;
int nums[1003];

// merge sort
void merge(int* nums, int left, int right) {
    int mid = left + (right - left) / 2;
    int p = left;
    int q = mid + 1;
    int tmp[1003] = {};
    int cur = 0;
    while (p <= mid && q <= right) {
        if (nums[p] < nums[q])
            tmp[cur++] = nums[p++];
        else
            tmp[cur++] = nums[q++];
    }
    if (p == mid + 1) {
        while (q <= right) tmp[cur++] = nums[q++];
    } else {
        while (p <= mid) tmp[cur++] = nums[p++];
    }
    for(int i=0,j = left;i<cur;i++,j++) nums[j] = tmp[i];
    return;
}

void mergeSort(int* nums, int left, int right) {
    if (left >= right) return;
    int mid = left + (right - left) / 2;
    mergeSort(nums, left, mid);
    mergeSort(nums, mid + 1, right);
    merge(nums, left, right);
}

// quick sort
void quickSort(int* nums, int left, int right){
    if(left >= right) return;
    int i = left;
    int j = right;
    int r = rand() % (right - left + 1) + left;
    swap(nums[left], nums[r]);
    while(i < j){
        while(nums[j] > nums[left] && i < j) j--;
        while(nums[i] <= nums[left] && i < j) i++;
        if(i < j) swap(nums[i], nums[j]);
    }
    swap(nums[left], nums[j]);
    quickSort(nums, left, j-1);
    quickSort(nums, j+1, right);
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> nums[i];
    bool tag;
    cin >> tag;

    quickSort(nums, 0, n - 1);
    if (tag) {
        for (int i = n - 1; i >= 0; i--) cout << nums[i] << " ";
    } else {
        for (int i = 0; i < n; i++) cout << nums[i] << " ";
    }

    return 0;
}